package Demo_02;

public class Singleton_02 {
    private static volatile Singleton_02 instance = null;
    private Singleton_02() {

    }
    public static Singleton_02 getInstance() {
        if(instance == null) {
            synchronized(Singleton_02.class) {
                if(instance == null) {
                    instance = new Singleton_02();
                }
            }
        }
        return instance;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            Thread thread = new Thread(() -> {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Singleton_02 instance = Singleton_02.getInstance();
                System.out.println(instance);
            });
            thread.start();
        }
    }
}
